#include "WMatrix.h"
#include <algorithm>

namespace ann
{

WMatrix::WMatrix( const unsigned int p_upCnt, const unsigned int p_dwCnt )
{
   assert( 0!=p_upCnt && 0!=p_dwCnt );
   m_upCnt = p_upCnt;
   m_dwCnt = p_dwCnt;

   m_weight = new double[p_upCnt*p_dwCnt];
   std::fill(m_weight, m_weight+p_upCnt*p_dwCnt, 0.0);
}

/*virtual*/ WMatrix::~WMatrix(void)
{
    if(NULL!=m_weight)
    {
        delete [] m_weight;
        m_weight = NULL;
    }
}

dVec& WMatrix::operator*( const dVec& p_Vec ) const
{
    assert( p_Vec.size() == m_dwCnt );

    dVec ret(m_upCnt, 0.0);
    double tSum = 0.0;

    for( unsigned int i = 0; i < m_upCnt; ++i )
    {
        tSum = 0.0;
        for( unsigned int j = 0; j < m_dwCnt; ++j )
        {
            tSum += (*this)(i,j) * p_Vec[j];
        }
        ret[i] = tSum;
    }

    return (*(new dVec(ret)));
}

dVec& WMatrix::GetCol( const unsigned int p_col ) const
{
    assert( p_col>0 && p_col<=m_dwCnt );

    dVec ret(m_dwCnt, 0.0);

    for( unsigned int i = 0; i < m_dwCnt; ++i )
    {
        ret[i] = (*this)(i, p_col);
    }

    return (*(new dVec(ret)));
}

}

